home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / MarkIt < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.3 KB  |  77 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    MarkIt
  3. #    MPW Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage:
  8. #            MarkIt [file…]
  9. #            
  10. #    Function:
  11. #            MarkIt creates markers for all C functions (either ANSI or old-style C) in the specified files.  
  12. #            If a file name is not given on the command line, MarkIt operates on the target file.
  13. #
  14. #    Note:
  15. #            MarkIt may be used with the Commando option.
  16. #----------------------------------------------------------------------------------------------------------------------------------------------------
  17.  
  18. # Don't exit script on error.
  19.     Set Exit 0
  20.  
  21. #    Initialize variables.
  22.     Set Files ""
  23.     Set Word '[a-zA-Z0-9_]+'
  24.  
  25. # If no parameter is given, set Files to the target file; otherwise set Files to the given parameters.
  26.     For file in {"Parameters"}
  27.         Set Files "{Files} '{file}'"
  28.     End
  29.     If {Files} == ""
  30.         Set Files "'{Target}'"
  31.     End
  32.     
  33. #    Loop through parameters
  34.     For fName in {Files}
  35.         #    Record whether fName is already open.
  36.             Set fullName "`Files -i -f "{fName}" ≥ Dev:Null`"
  37.             Set wasOpen `Evaluate "∂`Windows∂`" =~ /≈{fullName}≈/`
  38.             
  39.         # Open the file fName.  If the file can't be opened, print an error message and exit script.
  40.             Open "{fName}" ≥ Dev:Null
  41.             If {Status} != 0
  42.                 Echo "### {0}: File {fName} not found." 
  43.                 Continue
  44.             End >> Dev:StdErr
  45.         
  46.         # Go to the top of the input file.
  47.             Find • "{fName}"
  48.         
  49.         # Loop until no more functions in input file.
  50.             Loop
  51.         
  52.             # Position cursor at beginning of function.
  53.                 Find Δ/•{Word}[ ∂n∂t∂*a-zA-Z_0-9]*∂([ ∂t∂n∂*a-zA-Z_0-9∂[∂],]*[∂)][¬;∂)∂n]*∞/ "{fName}"
  54.                 
  55.             # Break if no more functions.
  56.                 Break If {Status}
  57.                 
  58.             # Select left paren.
  59.                 Find /∂(/ "{fName}"
  60.                 
  61.             # Select the first word preceding the left paren.
  62.                 Find \[¬ ∂t∂n]\:\[ ∂t∂n∂*]\!0 "{fName}"
  63.                 
  64.             # Create a marker with the name of the current function.  Overwrite any existing marker 
  65.             #    with the same name.
  66.                 Mark -y § "`catenate "{fName}.§"`" "{fName}"
  67.                 
  68.             # Position cursor at end of function.
  69.                 Find /∂{/ "{fName}"
  70.                 MatchIt -c "{fName}"
  71.             End
  72.             
  73.         #    Close the file if it wasn't open to start with.
  74.             If !"{wasOpen}"
  75.                 Close "{fName}" ≥ Dev:Null
  76.             End
  77.     End